package com.itheima.search.mq.listener;

import com.itheima.search.constants.MqConstants;
import com.itheima.search.service.SearchService;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class newsListener {

      private final SearchService searchService;
      @RabbitListener(bindings =@QueueBinding(
              value = @Queue(value = MqConstants.NEWS_QUEUE_ADD,durable = "true"),
              exchange = @Exchange(value = MqConstants.NEWS_EXCHANGE,type = ExchangeTypes.TOPIC),
              key = MqConstants.NEWS_ADD_KEY
      ))
      public void addNews(String news){
          searchService.addNews(news);
      }

      @RabbitListener(bindings =@QueueBinding(
              value = @Queue(value = MqConstants.NEWS_QUEUE_DEL,durable = "true"),
              exchange = @Exchange(value = MqConstants.NEWS_EXCHANGE,type = ExchangeTypes.TOPIC),
              key = MqConstants.NEWS_DEL_KEY
      ))
      public void delNews(Long newsId){
          searchService.delNews(newsId);
      }

      @RabbitListener(bindings =@QueueBinding(
              value = @Queue(value = MqConstants.NEWS_QUEUE_UPD,durable = "true"),
              exchange = @Exchange(value = MqConstants.NEWS_EXCHANGE,type = ExchangeTypes.TOPIC),
              key = MqConstants.NEWS_UPD_KEY
      ))
      public void updNews(String news){
            searchService.updNews(news);
      }

      @RabbitListener(bindings =@QueueBinding(
              value = @Queue(value = MqConstants.NEWS_QUEUE_INIT,durable = "true"),
              exchange = @Exchange(value = MqConstants.NEWS_EXCHANGE,type = ExchangeTypes.TOPIC),
              key = MqConstants.NEWS_INIT_KEY
      ))
      public void initNews(String newsList){
            searchService.initNews(newsList);
      }
}
